package morenoapp.util;

import java.awt.Component;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.plaf.basic.BasicComboBoxRenderer;

/**
 *
 * @author dmitry.mamonov
 */
public class DescriptionSupportComboBoxRenderer extends BasicComboBoxRenderer {
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if (value == null || value instanceof Description) {
            Description description = (Description) value;

            JComponent result = (JComponent) super.getListCellRendererComponent(list, description != null ? description.getShortTitle() : "", index, isSelected, cellHasFocus); //NOI18N
            result.setToolTipText(description != null ? "<html>" + description.getHtmlDescription() : null); //NOI18N

            return result;
        } else {
            throw new RuntimeException("Unsupported value type: " + value.getClass()); //NOI18N
        }
    }
}
